home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / hypercar / xcmd / xrulesde.sit / Xrules™ Tutorial / card_13931.txt < prev    next >
Encoding:
Text File  |  1991-06-24  |  4.5 KB  |  97 lines

  1. -- card: 13931 from stack: in
  2. -- bmap block id: 14240
  3. -- flags: 4000
  4. -- background id: 7050
  5. -- name: asserting facts
  6.  
  7.  
  8. -- part 1 (field)
  9. -- low flags: 01
  10. -- high flags: 0007
  11. -- rect: left=2 top=26 right=314 bottom=511
  12. -- title width / last selected line: 0
  13. -- icon id / first selected line: 0 / 0
  14. -- text alignment: 0
  15. -- font id: 22
  16. -- text size: 10
  17. -- style flags: 0
  18. -- line height: 13
  19. -- part name: doc
  20.  
  21.  
  22. -- part contents for card part 1
  23. ----- text -----
  24. Facts may be asserted by the inference engine within rules or daemons or they may be asserted external to the inference engine via response to a query.  
  25.  
  26. If you would like to assign the value of one fact to another you can use the following construct in the rule base:
  27.  
  28.     PUT FACT fact_id_1 INTO FACT fact_id_2   -- in the rule base
  29.  
  30. This example puts the value of fact "fact_id_1" into fact "fact_id_2".  Note that you cannot assign the value of one fact to another except in the rule base
  31. (you can't do it in response to a query).
  32.  
  33. You can change the values of facts when they have been previously asserted.  However, the inference engine will not re-examine or retract rules or their clauses that have already been processed.
  34.  
  35. You can retract a fact by assigning it a null value.  This is accomplished by answering a query with a carriage return or by using the following construct in the rule base: 
  36.  
  37.     PUT "" INTO FACT fact_id   -- in the rule base
  38.  
  39. Note that even though the system considers the fact not asserted when it is assigned a null value, the system will still process any daemons using that fact.
  40.  
  41. The response of the system to facts being retracted depends on whether it is forward or backward chaining.  The sections on forward and backward chaining document the responses for each case.
  42.  
  43. You may force a match by using the wildcard (*) operand.  The wildcard operand will match anything except a fact that is not asserted.  You may assign the wildcard operator to a fact by answering "*" to a query for the fact or by using the following construct in the rule base:
  44.  
  45.     PUT "*" INTO FACT fact_id
  46.  
  47. When the fact is compared to anything except a fact that is not asserted, it will evaluate true.  If it is compared to a fact that is not asserted, the system will cease evaluation of the rule if forward chaining or it will attempt to assert the fact if backward chaining, unless the immediate operator(#) is applied to the fact that is not asserted.
  48.  
  49. The following example illustrates the use of the wildcard operand.
  50.  
  51.     fact a "what is the value of a?"
  52.  
  53.     if
  54.       fact a = 123
  55.     then
  56.       put 1 into fact b
  57.  
  58. If you answer "*" when prompted for the value of "a", the rule will fire, setting fact "b" to 1.  When fact "a" is compared to anything except a fact that is not asserted, it will evaluate true.
  59.  
  60. Similarly, if you compare a fact to a wildcard, it will always evaluate true if it is asserted.  For example, assume the rule base contains the following:
  61.  
  62.     fact a "what is the value of a?"
  63.  
  64.     if
  65.       fact a = *
  66.     then
  67.       put 1 into fact b
  68.  
  69. If fact "a" was not asserted, the system would either attempt to assert fact "a" (if backward chaining with a goal of "b") or it would simply cease evaluation of the rule (if forward chaining).  If fact "a" was asserted, the system would consider the clause true regardless of the value of fact "a".
  70.  
  71. The immediate operator will force the inference engine to evaluate a fact at its current value.  The inference engine will not attempt to assert the fact. If the fact is not asserted, the inference engine will use the null string ("") as its value.  The following examples illustrates the use of the immediate operator:
  72.  
  73.     fact c "enter '1' as the value of c"
  74.  
  75.     rule "a null"
  76.     if
  77.       fact c = 1 and
  78.       #fact a = ""            -- if fact "a" is not asserted
  79.     then 
  80.       put "" into fact b
  81.  
  82.     rule "a asserted"
  83.     if  
  84.       fact c = 1 and
  85.       #fact a <> ""           -- if fact "a" is asserted
  86.     then 
  87.       put "" into fact b
  88.  
  89. When forward chaining, the system would assert fact "c" and then examine rule 
  90. "a null".  The rule "a null" would fire.   The system would then examine rule 
  91. "a asserted" which would prove false because fact "a" is not asserted.
  92.  
  93. When backward chaining (with a goal of "b") the system would assert fact "c" and then examine rule "a null".  The rule "a null" would fire.  The system would then examine rule "a asserted" which would prove false because fact "a" is not asserted.
  94.  
  95. The immediate operator has no effect when facts are already asserted, as the system would not have attempted to assert them anyway.
  96.  
  97.